from flask_sqlalchemy import SQLAlchemy
from flask import Flask
import redis
from flask_wtf.csrf import CSRFProtect
from flask_session import Session

app = Flask(__name__)

# 抽取配置类到新的模块中 并导入
# # 定义配置类
# class Config(object):
#     DEBUG = True
#     # 配置数据库信息
#     SQLALCHEMY_DATABASE_URI = 'mysql://root:9412@127.0.0.1:3306/flask_p1'
#     SQLALCHEMY_TRACK_MODIFICATIONS = False
#
#     # redis配置
#     REDIS_HOST = '127.0.0.1'
#     REDIS_PORT = 6379
#
#     # session配置
#     SECRET_KEY = "EjpNVSNQTyGi145247vWECj9TvC/+kq3oujeewtftgsM6xX9Yjq52v54g+HVoknA"
#     SESSION_TYPE = "redis"  # 指定 session 保存到 redis 中
#     SESSION_USE_SIGNER = True  # 让 cookie 中的 session_id 被加密签名处理
#     SESSION_REDIS = redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT)  # 使用 redis 的实例
#     PERMANENT_SESSION_LIFETIME = 86400  # session 的有效期，单位是秒
from settings import Config

app.config.from_object(Config)
db = SQLAlchemy(app)
redis_store = redis.StrictRedis(host=Config.REDIS_HOST, port=Config.REDIS_PORT)
CSRFProtect(app)
Session(app)